package com.yiyibook.util;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 〈功能简述〉
 *
 * @author xun.gong@hand-china.com
 * @date 2019/10/14
 */
public class FieldErrorMsg {

    public static Map<String, Object>  errorMsg(BindingResult result){
        Map<String, Object> map = new HashMap<>();
        List<FieldError> errors = result.getFieldErrors();
        for (FieldError error : errors) {
            System.out.println("错误的字段名：" + error.getField());
            System.out.println("错误信息" + error.getDefaultMessage());
            map.put(error.getField(), error.getDefaultMessage());
        }
        return map;
    }


}
